package com.winglish.as3.exam.opic 
{
	import com.winglish.as3.cookie.Cookie;
	import com.winglish.as3.flashplayer.FlashPlayer;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.external.ExternalInterface;
	
	/**
	 * ...
	 * @author charmjin
	 */
	public class OpicHelp extends MovieClip
	{
		private const cookieName:String = "winglishOpic";
		private var autoPopupOpen:MovieClip;
		
		public function OpicHelp() 
		{
		}
		
		/**
		 * 오픽 시험 전 안내 팝업창 자동 오픈 상태값.
		 * @return
		 */
		public function getHelpPopupAutoOpen():Boolean {
			var auto:Boolean = true;
			if (Cookie.getCookie(cookieName) == "true") auto = false;
			return auto;
		}
		/**
		 * 오픽 시험 전 안내 팝업창 "다음부터 이 창 열지 않기" 셋팅.
		 * @param	mc
		 */
		public function setHelpPopupAutoOpenChk(mc:MovieClip):void {
			autoPopupOpen = mc;
			if (Cookie.getCookie(cookieName) != "none") autoPopupOpen.gotoAndStop(2);
			autoPopupOpen.addEventListener(MouseEvent.CLICK, PopupAutoOpenBtnClick);
			autoPopupOpen.buttonMode = true;
		}
		
		/**
		 * "다음부터 이 창 열지 않기" 버튼 클릭 이벤트.
		 * @param	e
		 */
		private function PopupAutoOpenBtnClick(e:MouseEvent):void {
			if (e.currentTarget.currentFrame == 1) e.currentTarget.gotoAndStop(2);
			else e.currentTarget.gotoAndStop(1);
		}
		
		/**
		 * 오픽 시험 전 안내 팝업창 닫기 버튼 셋팅.
		 * @param	btn
		 */
		public function setHelpPopupClose(btn:SimpleButton):void {
			btn.addEventListener(MouseEvent.CLICK, helpPupupCloseBtnClick);
		}
		
		/**
		 * 오픽 시험 전 안내 팝업창 닫기 버튼 클릭 이벤트
		 * @param	e
		 */
		private function helpPupupCloseBtnClick(e:MouseEvent):void {
			if (autoPopupOpen.currentFrame == 1) Cookie.clearCookie(cookieName);
			else Cookie.setCookie(cookieName, "true");
			dispatchEvent(new Event("helpPopupClose"));
			
		}
		
		/**
		 * 플래시 플레이어 버전 셋팅.
		 * @param	txt
		 */
		public function setPlayerVersion(txt:TextField):void {
			txt.text = FlashPlayer.getShortversion();
		}
		
		/**
		 * flashPlayer 다운 버튼 셋팅.
		 * @param	btn
		 */
		public function setFlashPlayerDown(btn:SimpleButton):void {
			btn.addEventListener(MouseEvent.CLICK, flashPlayerDownClick);
		}
		
		/**
		 * flashPlayer 다운 버튼 클릭.
		 * @param	e
		 */
		private function flashPlayerDownClick(e:MouseEvent):void {
			var request: URLRequest = new URLRequest(FlashPlayer.playerDownUrl);
			navigateToURL( request, "_blank" );
		}
		
		/**
		 * 마이크 보안 설정 저장 팝업 셋팅.
		 * @param	btn
		 */
		public function setRecordHelpPopup(btn:SimpleButton):void {
			btn.addEventListener(MouseEvent.CLICK, RecordHelpPopupClick);
		}
		
		/**
		 * 마이크 보안 설정 저장 팝업 클릭
		 * @param	e
		 */
		private function RecordHelpPopupClick(e:MouseEvent):void {
			ExternalInterface.call( "micSecuritySet" );
		}
	}

}